﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="FindBill.aspx.cs" Inherits="sWarranty.WEB.FindBill" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <link rel="stylesheet" type="text/css" href="../CSS/Table.css" />
    <link rel="stylesheet" type="text/css" href="../CSS/Menu.css" />
    <script src="../JS/jquery-1.8.2.js" type="text/javascript"></script>
    <script src="../JS/notify.js" type="text/javascript"></script>
    <link href="../CSS/notify.css" rel="stylesheet" type="text/css" />
    <script src="../JS/jquery.tablesorter.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("table").tablesorter({ debug: false });
            checkFirstVisit();

        });

        function addtoReturn(a) {
            var span = document.getElementById('lblReturnValueBillTo');
            //var txt = document.getElementById('txtReturnValueBillTo');
            if (span.innerHTML.indexOf(a + ",") == -1)
                span.innerHTML += a + ",";
            //            if (txt.value.indexOf(a + ",") == -1)
            //                txt.value += a + ",";
        }
        function addtoReturnToLeft(a) {
            var span = document.getElementById('lbladdedValue');
            //var txt = document.getElementById('txtReturnValueBillTo');
            if (span.innerHTML.indexOf(a + ",") == -1)
                span.innerHTML += a + ",";
            //            if (txt.value.indexOf(a + ",") == -1)
            //                txt.value += a + ",";
        }

        function removeToReturn(a) {
            var span = document.getElementById('lblReturnValueBillTo');
            //var txt = document.getElementById('txtReturnValueBillTo');
            span.innerHTML = span.innerHTML.replace(a + ",", "");
            //txt.value = span.innerHTML;
        }
        function removeToReturnToLeft(a) {
            var span = document.getElementById('lbladdedValue');
            span.innerHTML = span.innerHTML.replace(a + ",", "");
            //var txt = document.getElementById('txtReturnValueBillTo');
            //txt.value = span.innerHTML;
        }

        function toogleReturnValue(id) {
            var t = $('#' + id).is(":checked")
            if (t == false) {
                removeToReturn(id);
                $('#' + id).attr('checked', false);
            }
            else {
                $('#' + id).attr('checked', true);
                addtoReturn(id);

            }
        }
        function toogleReturnValueToLeft(id) {
            var t = $('#chkRight_' + id).is(":checked")
            if (t == false) {
                removeToReturnToLeft(id);
                $('#chkRight_' + id).attr('checked', false);
            }
            else {
                addtoReturnToLeft(id);
                $('#chkRight_' + id).attr('checked', true);
            }
        }
        function setDefaul(a) {
            var txt = document.getElementById('txtReturnValueBillTo');
            if (txt.value.indexOf(a + ",") != -1) {
                //neu co' , remove , roi add len dau(set default nam o dau)
                txt.value = txt.value.replace(a + ",", "");
                txt.value = a + "," + txt.value;
            }
            else {
                // ko co', add moi, set len dau
                txt.value = a + "," + txt.value;

            }
        }
        function updateParentWindow(a) {
            var fName = a; //document.getElementById('dropShop2').value;     
            var arrayValues = new Array(fName);
            window.opener.updateValues(arrayValues);
            window.close();
        }
        function checkFirstVisit() {
            if (document.cookie.indexOf('mycookie2') == -1) { //first
                // cookie doesn't exist, create it now
                document.cookie = 'mycookie2=1';

            }
            else {
                //alert('You refreshed!');
                var txtReturnValueBillTo = $('#txtReturnValueBillTo').val();
                $('#lblReturnValueBillTo').text(txtReturnValueBillTo);

                var lines = txtReturnValueBillTo.split(',');
                var i = 0;
                $.each(lines, function (key, line) { //line la billcode
                    if (line != "") {
                        $("#tr" + line).hide();
                        if (i == 0)
                            $('#tblRight tr:last').after("<tr id='row_" + line + "'><td><input id='chkRight_" + line + "' onclick=\"toogleReturnValueToLeft('" + line + "')\" type='checkbox' /></td><td><input type='radio' checked='checked' name='group' onclick=\"setDefaul('" + line + "')\"/></td><td>" + line + "</td></tr>");
                        else
                            $('#tblRight tr:last').after("<tr id='row_" + line + "'><td><input id='chkRight_" + line + "' onclick=\"toogleReturnValueToLeft('" + line + "')\" type='checkbox' /></td><td><input type='radio' name='group' onclick=\"setDefaul('" + line + "')\"/></td><td>" + line + "</td></tr>");
                        i = "1";
                    }
                });

                var span = document.getElementById('lblReturnValueBillTo');
                span.innerHTML = "";
            }
        }
        function back() {
            var txt = document.getElementById('txtReturnValueBillTo');
            updateParentWindow(txt.value);
        }
        function moveToRigth() {
            // <tr id="trxx"> : left
            // <tr id="row_xx"> : right
            var span = document.getElementById('lblReturnValueBillTo');
            var addedValue = document.getElementById('lbladdedValue');
            var txt = document.getElementById('txtReturnValueBillTo');
            addedValue.innerHTML = "";
            var lines = span.innerHTML.split(',');
            $.each(lines, function (key, line) { //line la billcode
                if (line != "") {
                    $("#tr" + line).hide();
                    $('#tr' + line).attr('checked', false);
                    $('#tblRight tr:last').after("<tr id='row_" + line + "'><td><input id='chkRight_" + line + "' onclick=\"toogleReturnValueToLeft('" + line + "')\" type='checkbox' /></td><td><input type='radio' name='group' id='rad_" + line + "' onclick=\"setDefaul('" + line + "')\" /></td><td>" + line + "</td></tr>");
                }
            });
            txt.value += span.innerHTML;
            span.innerHTML = "";
            addedValue.innerHTML = "";
        }
        function moveToLeft() {
            var span = document.getElementById('lblReturnValueBillTo');
            var addedValue = document.getElementById('lbladdedValue');
            var lines = addedValue.innerHTML.split(',');
            var txt = document.getElementById('txtReturnValueBillTo');
            $.each(lines, function (key, line) { //line la billcode
                if (line != "") {
                    $("#row_" + line).hide();
                    $('#row_' + line).attr('checked', false);
                    $("#tr" + line).show();
                    txt.value = txt.value.replace(line + ",", "");
                    $("#tr" + line).removeAttr('checked');
                }
            });
            span.innerHTML = "";
            addedValue.innerHTML = "";
        }

        
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ksdjfl" runat="server">
    </asp:ScriptManager>
    <div style="display: none;">
        <asp:TextBox ID="txtReturnValueBillTo" runat="server" ClientIDMode="Static" Width="100%"></asp:TextBox>
    </div>
    <div class="TitleCont">
        Find Bill To
    </div>
    <div class="Mid2">
        <div class="Search2">
            <table id="newspaper-b">
                <tbody>
                    <tr>
                        <td class="BackGround-gray">
                            Bill Code
                        </td>
                        <td>
                            <asp:TextBox ID="txtBill" runat="server"></asp:TextBox>
                        </td>
                        <td class="BackGround-gray">
                            Name
                        </td>
                        <td>
                            <asp:TextBox ID="txtFullName" runat="server"></asp:TextBox>
                        </td>
                    </tr>
                    <%--<tr>
                        <td class="BackGround-gray">
                            Region
                        </td>
                        <td>
                            <asp:DropDownList ID="dropRegion" runat="server">
                                <asp:ListItem Value="0" Text="-- Select --"></asp:ListItem>
                                <asp:ListItem Value="NORTH" Text="NORTH"></asp:ListItem>
                                <asp:ListItem Value="MIDDLE" Text="MIDDLE"></asp:ListItem>
                                <asp:ListItem Value="SOUNTH" Text="SOUNTH"></asp:ListItem>
                            </asp:DropDownList>
                        </td>
                        <td class="BackGround-gray">
                            Representative
                        </td>
                        <td>
                            <asp:TextBox ID="txtRepresentative" runat="server"></asp:TextBox>
                        </td>
                    </tr>--%>
                    <tr>
                        <td colspan="4">
                            <input type="button" id="btnClose" onclick="javascript:window.close();" style="width: 80px;"
                                class="button Float-right" value="Close" />
                            <input type="button" id="btnSave" onclick="back()" style="width: 80px;" class="button Float-right"
                                value="Save" />
                            <asp:Button ID="btnFind" runat="server" Width="80px" CssClass="button Float-right"
                                Text="Search" OnClick="btnFind_Click" />
                            <div style="width: 70%; overflow: auto;">
                                <span id="lblReturnValueBillTo" style="display: none;"></span>
                            </div>
                        </td>
                    </tr>
                    <span id="lbladdedValue" style="display: none"></span>
                </tbody>
            </table>
            <div style='padding-bottom: 10px;'>
            </div>
            <div style="width: 100%;">
                <div id="tblLeft" runat="server" class="b" style="float: left; margin-left: 5px;
                    height: 400px; overflow: auto; width: 73%">
                    <table id="newspaper-b">
                        <thead>
                            <tr>
                                <th scope="col">
                                    Select
                                </th>
                                <th scope="col">
                                    Bill Code
                                </th>
                                <th scope="col">
                                    Full name
                                </th>
                            </tr>
                        </thead>
                        <tbody>
                            <asp:Literal ID='litData' runat='server'></asp:Literal>
                        </tbody>
                    </table>
                </div>
                <div style="padding-top: 15%; float: left; margin-left: 5px; height: 400px; overflow: auto;
                    text-align: center; width: 5%;">
                    <table id="Table1">
                        <tr>
                            <td>
                                <input type="button" value=">" style="width: 40px" class="button" onclick="moveToRigth()" />
                                <div style='height: 3px;'>
                                </div>
                                <input type="button" value="<" style="width: 40px" class="button" onclick="moveToLeft()" />
                            </td>
                        </tr>
                    </table>
                </div>
                <div runat="server" style="float: left; margin-left: 5px; height: 400px; width: 20%;
                    overflow: auto;">
                    <table id="tblRight" class="b" summary="Table after select">
                        <thead>
                            <tr>
                                <th scope="col">
                                    Select
                                </th>
                                <th scope="col">
                                    Default
                                </th>
                                <th scope="col">
                                    Bill Code
                                </th>
                            </tr>
                        </thead>
                        <tbody>
                            <asp:Literal ID='litExistsBillTo' runat="server"></asp:Literal>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        <div class="Clear_both">
        </div>
    </div>
    </form>
</body>
</html>
